package com.hyzh.latte.sand.socket;



import com.coffee.socketio.command.CommandEnum;
import com.coffee.socketio.metadata.MessageType;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author: songkui
 * @since: 2024/3/22 9:14
 */
public enum SandCommandType implements CommandEnum {

    PcRelay(666,  SandEventType.PC_RELAY_TYPE),
    mtRelay(777, SandEventType.MT_RELAY_TYPE)
    ;

    public String namespace;
    public String event;
    public int cmd;
    private boolean verifyType;
    private MessageType messageType;
    private final Class request;

    SandCommandType(int cmd, SandEventType eventType) {
        this.namespace = "";
        this.event = eventType.event();
        this.cmd = cmd;
        this.request = eventType.request();
        this.verifyType = false;
        this.messageType = MessageType.Json;
    }


    @Override
    public String namespace() {
        return this.namespace;
    }

    @Override
    public String event() {
        return this.event;
    }

    @Override
    public int cmd() {
        return this.cmd;
    }

    @Override
    public String cmdName() {
        return this.name();
    }

    @Override
    public Class request() {
        return this.request;
    }


    @Override
    public boolean verifyType() {
        return this.verifyType;
    }

    @Override
    public MessageType messageType() {
        return this.messageType;
    }


    //转换成 map
    private static Map<Integer, CommandEnum> handlerTypeMap = Arrays.stream(SandCommandType.values())
            .collect(Collectors.toMap(SandCommandType::cmd, rtype -> rtype));

    public static SandCommandType valueOfCode(int cmd) {
        return (SandCommandType) handlerTypeMap.get(cmd);
    }

    public static Map<Integer, CommandEnum> getMap() {
        return handlerTypeMap;
    }


}
